<?php
/**
 * 门店扫码转让店长
 * Class CouponAfterScan
 */
namespace Scan;


use Model\StoreStaffMod;
use Pub\cache\Cache;

class TransferScan extends Scan
{
    private $_store_id = 0;  //门店id

    private $StoreStaff = null;  //门店员工
    public function __construct()
    {
        global $_GPC;
        parent::__construct();
        $this->StoreStaff = new StoreStaffMod();
        $this->_store_id = $_GPC['store_id'];
    }

    public function index()
    {
        global $_W;
        if($this->testOtherSotreStaff()){
            return array('status'=>'error','err_msg'=>'您已经是某门店的职员了');
        }
        $_data = array(
            'user'=>array(
                'id'=>$this->_scan_uid,
                'nickname'=>$this->_nickname,
                'header'=>$this->_header
            ),
            'past_time'=>TIMESTAMP+60*5  //有效期5分钟
        );
        Cache::set(Cache::STORE_TRANSFER,$_data,array('store_id'=>$this->_store_id));
        return array('status'=>'success','success_msg'=>'申请店长成功，等待审核');
    }

    /**
     * 检测扫码用户是不是其他门店的员工，如果时其他门店员工，拒绝申请
     */
    private function testOtherSotreStaff()
    {
        return $this->StoreStaff->findOne(array('uid'=>$this->_scan_uid,'uniacid'=>$this->_uniacid),array('id'));
    }

}
